//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:2020/9/11
// @Time:1:46 下午
//
//

#ifndef GEEJOAN_APPMANAGER_H
#define GEEJOAN_APPMANAGER_H

#include <mutex>
#include <functional>
namespace GeeJoan
{
    class Global_Context;

    class ThreadPool;

    class NetworkManager;

    class ModManager;

    class BaseMod;

    class AppManager;


    using AppManagerCallbackFunction = std::function<void(AppManager *appManager )>;

    class AppManager
    {
    private:
        Global_Context *globalContext = nullptr;
        std::mutex m_mutex;
        NetworkManager *networkManager = nullptr;
        ThreadPool *m_threadPool = nullptr;
        ModManager *modManager = nullptr;
        void *m_io_context = nullptr;
        std::string m_logPath;
        int port = 10000;
    public:
        void setPort(int port);

        AppManager();

        void init_local();

        int init_network();

        int call_init_success();

        void stop();

        void run();

        void setLogPath(const std::string &mLogPath);

        bool registerModFunc(GeeJoan::BaseMod *mod, bool auto_del = true);


        /**
         * 事件触发监听器
         */
        AppManagerCallbackFunction init_before_callback = nullptr; ///< 初始化之前
        AppManagerCallbackFunction init_after_callback = nullptr;
        AppManagerCallbackFunction init_success_before_callback = nullptr; ///< 初始化完成之前
        AppManagerCallbackFunction init_success_after_callback = nullptr;
        AppManagerCallbackFunction delete_before_callback = nullptr; ///< 对象释放之前
        AppManagerCallbackFunction delete_after_callback = nullptr;



        virtual ~AppManager();
    };
}

#endif //GEEJOAN_APPMANAGER_H
